/**
 * 工具类
 */
import Vue from "vue";
import CryptoJS from "crypto-js";
let keyStr = "xUV7nHiE2mkTGGo="; //加密密钥
let ivStr = "a1s2d3f4g5h6j7k8"; //矢量

//加密
export function aes_encrypt(word) {
  var key = CryptoJS.enc.Utf8.parse(keyStr);
  var iv = CryptoJS.enc.Utf8.parse(ivStr);
  // var srcs = CryptoJS.enc.Utf8.parse(word);
  var encrypted = CryptoJS.AES.encrypt(word, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return encrypted.toString();
}

//解密
export function aes_decrypt(word) {
  var key = CryptoJS.enc.Utf8.parse(keyStr); //
  var iv = CryptoJS.enc.Utf8.parse(ivStr);
  // const restoreBase64 = word.replace(/\-/g,'+').replace(/_/g,'/');
  var restoreBase64 = word.replace(/[\r\n]/g, "");

  var decrypt = CryptoJS.AES.decrypt(restoreBase64, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}

export function decryptPhone(number){
  if(number){
    return aes_decrypt(number)
  }else{
    return ''
  }
}